from machine import I2C, Pin

from ssd1306 import SSD1306_I2C

i2c = I2C(id(0), sda=Pin(26), scl=Pin(27), freq=400000)
'''
每行12.5个字符
一行16个
最多4行
第一行为黄色，下三行为蓝色
'''
oled = SSD1306_I2C(128, 64, i2c)


def write_app(input: list):
    """直接重写全部"""
    if len(input) > 4:
        input = input[0:4]
        print("超出最大长度了")
    oled.fill(0)
    for i in range(len(input)):
        oled.text(str(input[i]), 0, i * 16)
    oled.show()


write_list = []


def add_write_message(input: str):
    """一行一行的写"""
    global write_list
    write_list.append(input)
    write_list = write_list[-4:]
    oled.fill(0)
    for i in range(len(write_list)):
        oled.text(str(write_list[i]), 0, i * 16)
    oled.show()
